//
//  SinaBaseViewController.swift
//  MySinaWeiBoSwiftProject
//
//  Created by apple on 2016/11/13.
//  Copyright © 2016年 WangChen. All rights reserved.
//

import UIKit

class SinaBaseViewController: UIViewController,VisitorViewBtnClickProtocol {

    //定义用户是否登录
    var isLogin: Bool = SinaUserAccountViewModel.shared.userLogin
    //懒加载访客视图
    lazy var visitorView: SinaNoLoginView = SinaNoLoginView()
    
    //导航栏
    lazy var naviBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
    //自定义导航数据源
    lazy var naviItem = UINavigationItem()
    
    //自定义title
    override var title: String?{
        
        didSet{
            
            naviItem.title = title
            
        }
        
    }
    
    //设置导航栏
    func setNavi() {
        
        self.navigationController?.navigationBar.isHidden = true
        self.view.addSubview(naviBar)
        naviBar.items = [naviItem]
        
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }


    // MARK:
    // MARK: - 在loadView的方法中根据是否已登录来判断是否加载访客视图
    override func loadView() {
        
        if isLogin == true {
            super.loadView()
            setNavi()
            return
        }
        
        //加载访客视图
        view = visitorView
        visitorView.delegate = self
        setNavi()
        
        
        
    }
    
    
    
    // MARK:
    // MARK: - 实现按钮点击协议代理方法
    func loginBtnDidClick() {
        print("点击了登录按钮")
        
        //进入OAuth界面
        let oAuth = SinaOAuthViewController()
        let oAuthNavi = UINavigationController(rootViewController: oAuth)
        present(oAuthNavi, animated: true, completion: nil)
        
    }
    func registerBtnDidClick() {
        print("点击了注册按钮")
    }
    
    
}
